<script setup>
import { queryCategoryApi } from '@/api/Category';
import { onMounted, ref } from 'vue'; // 添加 ref 的导入

const data = ref([]);
const loadCategory = async () => {
  const res = await queryCategoryApi();
  data.value = res;
  console.log(res);
}

const handleNodeClick = (data) => {
  console.log(data);
}

const defaultProps = {
  children: 'children',
  label: 'name',
}

// 修正 onMounted 的使用
onMounted(() => {
  loadCategory()
})
</script>

<template>
 <el-tree
    style="max-width: 600px"
    :data="data"
    :props="defaultProps"
    @node-click="handleNodeClick"
  />
</template>

<style scoped>
</style>